﻿using SMDB_Connect.SMDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace GS_OM
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            Session["SID"] = null;
            if (Request.Form.Count > 0)
                UserLogin(Request.Form[0], Request.Form[1]);
        }

        private void UserLogin(string UserName, string Passwrod)
        {
            SMDB_Mgr Mgr = new SMDB_Mgr();
            dynamic AccountDy = Mgr.LoginCheck(UserName, Passwrod);

            if (AccountDy == null)
            {
                Response.Write("用户名和密码不匹配");
                Response.End();
                return;
            }
            DBOAccount Account = AccountDy as DBOAccount;
            if (Request.Form[2] == "true")
            {
                HttpCookie CKS = new HttpCookie("CKS");
                CKS.Values.Add("CID", Account.Acc_ID.ToString());
                CKS.Values.Add("Pwd", Passwrod);
                CKS.Expires = DateTime.Now.AddDays(30);
                Response.AppendCookie(CKS);              //设置Cookies
            }
            Session["SID"] = Account.Acc_ID;                     //设置Session
            Session["SName"] = Account.Acc_Name;
            Response.Write("true");
            Response.End();
        }
    }
}